<?php
session_start();
	require_once "includes/config.php";
	require_once "includes/pagination.php";
    $itemPerPage=10;	
	
	$sg = $_REQUEST['sg2'];
	$key = $_REQUEST['key'];
	//$state = $_GET['state'];
	//$city = $_GET['city'];
	//$priceFrom = $_GET['priceFrom'];
	//$priceTo = $_GET['priceTo'];
	
	if(!empty($sg)) 
	{	
	
	 
		$sqlSelPro="SELECT *, tbl_wholeseller_product.product_name, tbl_users.user_id 
					FROM tbl_wholeseller_product, tbl_users 
					WHERE tbl_users.user_id=tbl_wholeseller_product.posted_by ";	
	
		$searchIncludes="";														
				
		  if($key!='')
		     $sqlSelPro.="  AND  tbl_wholeseller_product.product_name LIKE '%$key%' "; 
		    
		 
		/* else
		{
		$sqlSelPro="SELECT * FROM tbl_product";
		$pagelink="srch&sg";
	} */
  }
	$pLink = "srchwhole=1&sg2=$sg";	
	
	$pos     = strripos($sqlSelPro, "where");
	$curDate = date("Y-m-d G:i:s",time());
	//echo $curDate;
	
	//echo $sqlSelPro;
?>	
<div id='panel'>
<table>
	<tr>
		<td colspan="2" valign="top">	
					
		<div style="width: 950px; float: left; margin:10px 0px 5px 0px;">
		
		
						
	   	</div>
		</td>
	</tr>
</table>

<table width="100%" border="0">

<tr>

<td>
<div style="width: 950px; float: left; vertical-align: top;">

	<div style="width: 950px; float: left; margin:10px 0px 5px 0px;">	
			<a href="#">
				<img src="images/arrow_back.png" style="border:none; margin:0px 5px 0px 0px;" />
				Back to Search Results
			</a>&nbsp;&nbsp;&nbsp;|&nbsp;
			<font style="color:#1DA9E2;">
				Listed in Category: Blue Ray &amp; DVD Player
			</font>				
	</div>

	<div class="mypg_left_out">
			<table style="width:100%">
			<?php
			 if($userType=='3' || $userType=='5')
			 {
			 ?>
			<tr>
				<td>
					<div class="fulldiv">
						<p style="color:#000000; font-size: 12px; font-weight: normal;">
						<?php echo $business_name ?><br />
						<?php echo $address_line_1 ?><br />
						</p>
					</div>
				</td>
			</tr>
			<?
			 }
			 ?>
			<tr>
				<td width="214" valign="top">
				<p style="color:#767676; font-size: 14px; font-weight: normal; margin:5px 0px 5px 0px;">
					Refine Search
				</p>
				<div class="shourtbox">
				<table width="100%" border="0">
			<?php if($offerSettings)
			{
			?>
			<tr>
				<td><table width="212"  border="0" cellpadding="0" cellspacing="0">
				  <tr>
					<td></td>
				  </tr>
				  <tr>
					<td style=" background-image:url(images/LHS_menu_top.jpg); height:10px"></td>
				  </tr>
				  <tr>
					<td height="30" style=" background-image:url(images/LHS_gradient_bg.jpg); background-repeat:repeat-y;height:100px; vertical-align:top;"><div id="category-title">Offer from <?php echo $sellerName; ?> </div>
						<br />
					  <div id="category-content"><?php echo $offer; ?></div>
					  </td>
				  </tr>
				  <tr>
					<td style=" background-image:url(images/LHS_menu_bottom.jpg); height:18px"></td>
				  </tr>
				</table></td>
			  </tr>
			  <tr>
				<td>&nbsp;</td>
			  </tr>
			  <?php } ?>
			  <tr>
				<td><table width="212"  border="0" cellpadding="0" cellspacing="0">
							  
				  <tr>
					<td style="vertical-align:top;">
					<div id="category-title">Search Within Store</div>
						<br />
					  <div class="fulldiv">
					  <center>
						<form action="" method="post" name="formShopSearch" id="formShopSearch">
							<input type="text" name="search_string" id="search_string" class="inputbg" style="width:120px; float:left;" />
							<input type="submit" name="search" value="Search" class="yellow_btn" style="height:30px; margin:0px 0px 0px 10px;" />
						  </form>
					  </center>
					  </div>
					 </td>
				  </tr>
				  
				  <tr>
					<td style="vertical-align:top;"><br />
					<div id="category-title">Category</div>
						<br />
					  
						<form action="" method="post" name="formShopSearch" id="formShopSearch">
							<select name="pro_subcategory" id="pro_subcategory" class="inputbg" onChange="getsubsearch(this.value);">
								<option value="" selected="selected">Select Category</option>
								<option value="" selected="selected">Category1</option>
								<option value="" selected="selected">Category2</option>
								<option value="" selected="selected">Category3</option>
							</select>
						</form><br />
					 
					 </td>
				  </tr>
				   
				  <tr>
					<td style="vertical-align:top;"><br />
					<div id="category-title">Sub-Category</div>
						<br />
					  
						<form action="" method="post" name="formShopSearch" id="formShopSearch">
							<select name="pro_subcategory" id="pro_subcategory" class="inputbg" onChange="getsubsearch(this.value);">
								<option value="" selected="selected">Select Sub-Category..</option>
							<?php
							$sel="";
							$sql_shocat="SELECT * FROM tbl_category where parent_id='1'";
							$rst_shocat=mysql_query($sql_shocat);
							while($row_shocat=mysql_fetch_array($rst_shocat)) {
								 $cat_id=$row_shocat['category_id'];
								 $cat_name=$row_shocat['category_name'];
								 if(isset($_GET['subcatid']))
								 {
								  echo $_GET['subcatid'];
								 if($_GET['subcatid']==$cat_id)
								  echo $sel="selected='selected'";
								  else
								   $sel="";
								 }
								 
								 echo "<option value='$cat_id' ".$sel.">$cat_name</option>";
							}
							?>
							</select>
						</form><br /> <br />
					 
					 </td>
				  </tr>
				   
				  <tr>
					<td style="vertical-align:top;">
					<div id="category-title">By Price</div>
					<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=1">under - $10</a></p>  
					<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=2">$10 - $50</a></p>  
					<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=3">$50 - $100</a></p>  
					<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=4">$100 - $500</a></p> 
					<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=5">$500 +</a></p>           
					 </td>
				  </tr>
				  
				</table></td>
			  </tr>
			</table>
				</div>
				</td>
			</tr>
			
			<tr>
				<td>
					<div class="text_box2" style="text-align:center;">
					The more products you pick up the more sales you will have
					</div>
				</td>
			</tr>
			
			</table>
	</div>
		
		

	<div class="fullbox_out">
	
	<div class="fulldiv">
		<strong class="orangehead">
			Search Results <?php if(!empty($searchFor)) echo " - ".$searchFor; ?>
		</strong>
	</div>
	
	<div class="fulldiv">
			<table align="center" width="100%" border="0">
				<tr>
					<td width="15%">Sort Options:</td>
					<td width="15%"><a href="#">Best Match</a></td>
					<td width="15%"><a href="#">General</a></td>
					<td width="15%"><a href="#">Local Only</a></td>
					<td width="30%">
						<div class="greytab_out" style="margin:0px 5px -9px 5px;">
							<div class="greytab_left">&nbsp;</div>
							<div class="greytab_repeat" style="cursor:pointer;" onclick="window.location='index.php?<?php echo $pLink;?>&sortby=price'">Sort price</div>
							<div class="greytab_right">&nbsp;</div>
						</div>
					</td>
				</tr>
			</table>
	</div>
	 <?php 		   
		 if(!empty($_GET['sortby'])) {
			      if($_GET['sortby']=='lps') {
				      $sqlSelPro .= " order by tbl_wholeseller_product.product_price ASC";		
			      }
			      else if($_GET['sortby']=='hps') {
				      $sqlSelPro .= " order by tbl_wholeseller_product.product_price DESC";		
			      }
			      else if($_GET['sortby']=='bm') {
				      $sqlSelPro .= " order by field(tbl_wholeseller_product.product_name, '$key') DESC";		
			      }
			      else if($_GET['sortby']=='gen') {
				      $sqlSelPro .= " order by tbl_wholeseller_product.product_id ASC";		
			      }
			      
		 }		
		 $rstSelPro=mysql_query(getPagingQuery($sqlSelPro,$itemPerPage));			  
		 $num=mysql_num_rows($rstSelPro);				   
		 if($num==0)
		      {					
			      ?><div class="fulldiv">
			      <div class="fullbox_top"></div>
			      <div class="fullbox_repeat">
			      <?php	echo "&nbsp;&nbsp;No Products Found...";?>
			      </div>
				      <div class="fullbox_bot"></div>
			      </div>
		      <?	
		       
		      }
		 else {
		  
		   while($rowSelPro=mysql_fetch_array($rstSelPro))
		   {							   
			$productId=$rowSelPro['product_id'];
			$postedby=$rowSelPro['posted_by'];
			$itemId=$rowSelPro['product_id'];
			$productName=wordFormater($rowSelPro['product_name'],20);
			$productTitle = $rowSelPro['product_name'];					   
			$productPrice=$rowSelPro['product_price'];
			$postedDate=$rowSelPro['posted_date'];
			     $productCode=$rowSelPro['product_code'];
			
			$pimage = getWholeProductImage($itemId,'p');
			if($pimage['thumb']!="") {
				     $productThumb = $pimage['thumb'];
			} else {
				     $productThumb="images/no_image.gif";	
			}
		  
		  ?>
	         <div class="fulldiv">
			<div class="fullbox_top"></div>
			<div class="fullbox_repeat">
				<div class="sellpro_table">
					<div class="sellpro_row1">
						<img src="<?php echo $productThumb?>">
					</div>
					
					<div class="sellpro_row2">
						<p class="sellpro_head" style="margin:5px 0px 5px 0px;">
						<a href="#" class="sellpro_head"> <?php echo $productTitle?> </a>
						</p>
						<i>product owner - Quveno95</i><br>
						<i>local pick up - <font style="color:#000000;">available</font></i>
					</div>
					
					<div class="sellpro_row3" style="text-align:center;">
						<p class="pro_ptag">
						<img src="images/w.png" />
						</p>
						<p class="pro_ptag">
							<a class="bluelink" href="#">chat available&nbsp;
							<img src="images/exclamation.png" style="border:0;" />
							</a>
						</p>
						
						<p style="font-size:12px;" class="pro_ptag">
							<span id="distance"></span>&nbsp;
							<p style="font-size: 12px;" class="pro_ptag">
								<i>miles away - </i><br><font style="color: #000000;">9 miles</font>&nbsp;
								<font style="color:#000000;">(<a href="javascript:void(0)" class="bluelink">map it</a>)</font>
							</p>
						</p>
					</div>
					
					
					<div class="sellpro_row2" style="text-align:right; font-size:12px;">
						<p style="margin: 5px 0px; font-size: 12px;" class="redtxt">
								$189.5 +<font style="color: #000000;"> $25.00 S &amp; h</font>
						</p>
						<p style="margin: 5px 0px;">minimum quantity&nbsp;&nbsp;<i>Per Order: 5</i></p>
						<p style="margin:5px 0px 5px 0px;"><a href="#" style="font-size:14px; font-weight:bold;">ADD TO CART</a></p>
					</div>
					
				</div>
			</div>
			<div class="fullbox_bot"></div>
	</div>
					
	<table width="100%" border="0">
	  
	  <tr>
		<td>
	
			
				
						   <br><table width='90%' border='0' align='center' cellspacing='0'>
								   <tr>
									<td colspan='5'>&nbsp;									</td>
								   </tr>
								   <tr class='head-tr'>
									  <td height='26' width='68'>&nbsp;</td>
									  <td width='138'><strong>Product Code </strong></td>
									  <td width='138'> <strong>Product name </strong></td>
									 <td width='90'> <strong>--</strong> </td>
									 <td width='54'> <strong>Price</strong> </td>
							 </tr>
							<?php	
							
							 while($rowSelPro=mysql_fetch_array($rstSelPro))
								 {							   
							   $productId=$rowSelPro['product_id'];
							   $postedby=$rowSelPro['posted_by'];
							   $itemId=$rowSelPro['product_id'];
							   $productName=wordFormater($rowSelPro['product_name'],20);
							   $productTitle = $rowSelPro['product_name'];					   
							   $productPrice=$rowSelPro['product_price'];
							   $postedDate=$rowSelPro['posted_date'];
								$productCode=$rowSelPro['product_code'];
							   
							   $pimage = getWholeProductImage($itemId,'p');
							   if($pimage['thumb']!="") {
									$productThumb = $pimage['thumb'];
							   } else {
									$productThumb="images/no_image.gif";	
							   }
							   ?>  
							   <tr>
									<td height='106' valign="top">
										<div align='center'><img src='<?php echo $productThumb; ?>'></div>								 </td>								 
									 <td style='vertical-align:top; padding:10px;'><a href='index.php?wholeproducts=<?php echo $itemId; ?>' title='<?php echo $productTitle; ?>'> <?php echo $productCode; ?> </a> </td>
									 <td style='vertical-align:top; padding:10px;'> <a href='index.php?wholeproducts=<?php echo $itemId; ?>' title='<?php echo $productTitle; ?>'> <?php echo $productName; ?> </a> </td>
									 <td style='vertical-align:top; padding:10px;'><input type='image' src='images/buy.gif' style='cursor:pointer;' onClick=''></td>
									  <td style='vertical-align:top; padding:10px;'>$<?php echo number_format($productPrice,2); ?><br /><?php if($_SESSION['user_id_sess']) {?><A HREF="javascript:void(0)" onclick="window.open('sendowner.php?ownerid=<?php echo $postedby;?>&productid=<?php echo $productId;?>','welcome','width=500,height=300')">Message</A><?php } else {?><A HREF="index.php?signin">Message</A><?php }?></td>
							   </tr>	
								   <tr>
										 <td colspan='5'> <div style='border-top:1px solid #CCCCCC;'> </div> </td>
								   </tr>				 	
							 <?php } ?>				 
							</table>
			<?php } ?>
		
		  <tr>
				<td><div align="center"><?php
					   $link=$pLink;
					   echo $disp=getPagingLink($sqlSelPro,$itemPerPage,$link);							   
				 ?></div>
				</td>
		  </tr>
		  </td>
		  </tr>
		</table>
	</div>
</div>
	</td>
  </tr>
</table>
</div>